#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<unordered_map>
#include<vector>
using namespace std;
class Solution {
public:
    int subarraysDivByK(vector<int>& nums, int k) {
        unordered_map<int, int> aw;
        aw[0 % k] = 1;
        int sum = 0, ret = 0;
        for (int i = 0; i < nums.size(); i++)
        {
            sum += nums[i];
            int r = (sum % k + k) % k;
            if (aw[r]) ret += aw[r];
            aw[r]++;
        }
        return ret;
    }
};